package br.edu.ufcg.greengrid.event.reader;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public abstract class EventReader<E> {

	public EventReader() {
	}

	public List<E> read(File input) throws IOException {
		BufferedReader br = null;
		String line = null;
		List<E> events = new ArrayList<E>();

		try {
			br = new BufferedReader(new FileReader(input));

			while ((line = br.readLine()) != null) {
				E event = getEvent(line);
				if(run(event)){
					events.add(event);
				}
			}

		} finally {
			if (br != null) {
				br.close();
			}
		}
		return events;
	}

	protected abstract E getEvent(String line);
	
	protected boolean run(E event){
		
		return true;
	}

}
